package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AssignmentProblems;
import com.ruoyi.system.service.IAssignmentProblemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作业题目Controller
 * 
 * @author ruoyi
 * @date 2025-08-15
 */
@RestController
@RequestMapping("/system/problems")
public class AssignmentProblemsController extends BaseController
{
    @Autowired
    private IAssignmentProblemsService assignmentProblemsService;

    /**
     * 查询作业题目列表
     */
    @PreAuthorize("@ss.hasPermi('system:problems:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssignmentProblems assignmentProblems)
    {
        startPage();
        List<AssignmentProblems> list = assignmentProblemsService.selectAssignmentProblemsList(assignmentProblems);
        return getDataTable(list);
    }

    /**
     * 导出作业题目列表
     */
    @PreAuthorize("@ss.hasPermi('system:problems:export')")
    @Log(title = "作业题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssignmentProblems assignmentProblems)
    {
        List<AssignmentProblems> list = assignmentProblemsService.selectAssignmentProblemsList(assignmentProblems);
        ExcelUtil<AssignmentProblems> util = new ExcelUtil<AssignmentProblems>(AssignmentProblems.class);
        util.exportExcel(response, list, "作业题目数据");
    }

    /**
     * 获取作业题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:problems:query')")
    @GetMapping(value = "/{assignmentProblemId}")
    public AjaxResult getInfo(@PathVariable("assignmentProblemId") Long assignmentProblemId)
    {
        return success(assignmentProblemsService.selectAssignmentProblemsByAssignmentProblemId(assignmentProblemId));
    }

    /**
     * 新增作业题目
     */
    @PreAuthorize("@ss.hasPermi('system:problems:add')")
    @Log(title = "作业题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssignmentProblems assignmentProblems)
    {
        return toAjax(assignmentProblemsService.insertAssignmentProblems(assignmentProblems));
    }

    /**
     * 修改作业题目
     */
    @PreAuthorize("@ss.hasPermi('system:problems:edit')")
    @Log(title = "作业题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssignmentProblems assignmentProblems)
    {
        return toAjax(assignmentProblemsService.updateAssignmentProblems(assignmentProblems));
    }

    /**
     * 删除作业题目
     */
    @PreAuthorize("@ss.hasPermi('system:problems:remove')")
    @Log(title = "作业题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assignmentProblemIds}")
    public AjaxResult remove(@PathVariable Long[] assignmentProblemIds)
    {
        return toAjax(assignmentProblemsService.deleteAssignmentProblemsByAssignmentProblemIds(assignmentProblemIds));
    }
}
